package com.movitech.mobile.cz.base.sys.bizcontroller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.movitech.mobile.cz.base.common.upload.UploadFile;
import com.movitech.mobile.cz.base.common.upload.UploadResultVO;
import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;

import io.swagger.annotations.Api;

/**
 * Created by Administrator on 2018/3/1.
 */
@RestController
@RequestMapping("/v1/public/upload")
@Api(value = "公共文件上传接口", description = "公共文件上传接口")
public class UploadController{

    @Autowired
    @Qualifier("uploadFile")
    private UploadFile uploadFile;
    
	@ResponseBody
	@RequestMapping(value = "/upload", method = RequestMethod.POST)
	public RestReturnResult<Object> upload(HttpServletRequest request,@RequestParam("file") List<MultipartFile> file) {
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL);
		try {
//			Map<String, MultipartFile> mapMultipartFile = ((MultipartHttpServletRequest)request).getFileMap();
			List<UploadResultVO> lstUploadResultVO = uploadFile.doFileUpload(file);
			if (!CollectionUtils.isEmpty(lstUploadResultVO)) {
				hResult = new RestReturnResult<Object>(CommonConstants.SUCCESS, lstUploadResultVO);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return hResult;
	}

}
